package com.mingtu.jgspatrol.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.SPStaticUtils;
import com.mingtu.bio.bean.AnimalResourceBean;
import com.mingtu.jgspatrol.R;
import com.mingtu.jgspatrol.databinding.ItemCenterDataBinding;
import com.mingtu.jgspatrol.holder.BaseViewBindingHolder;
import com.mingtu.jgspatrol.utils.MySPTools;

import java.util.List;

public class CenterDataAdapter extends RecyclerView.Adapter<BaseViewBindingHolder> implements View.OnClickListener {

    private Context context;
    private OnItemClickListener mOnItemClickListener = null;

    private String[] textArray = {"我的记录", "离线地图", "权限设置", "我的发现", "识别馆"};
    private int[] imgArrat = {R.mipmap.icon_center_track, R.mipmap.icon_center_offline_map, R.mipmap.icon_center_auth_set,
            R.mipmap.icon_center_my_find, R.mipmap.icon_center_ai_record};

    public CenterDataAdapter(Context context) {
        this.context = context;
    }

    @Override
    public BaseViewBindingHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        // 实例化展示的view
//        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_center_data, parent, false);
        ItemCenterDataBinding binding = ItemCenterDataBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        // 实例化viewholder
        BaseViewBindingHolder viewHolder = new BaseViewBindingHolder(binding);
        viewHolder.itemView.setOnClickListener(this);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(BaseViewBindingHolder holder, int position) {
        ItemCenterDataBinding binding = (ItemCenterDataBinding) holder.getBinding();
        binding.ivImg.setBackgroundResource(imgArrat[position]);
        binding.tvText.setText(textArray[position]);
        //将position保存在itemView的Tag中，以便点击时进行获取
        holder.itemView.setTag(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return imgArrat.length;
    }

    @Override
    public void onClick(View v) {
        if (mOnItemClickListener != null) {
            //注意这里使用tag方法获取position
            mOnItemClickListener.onItemClick(v, (int) v.getTag());
        }
    }

    public void upData(List<AnimalResourceBean.PageBean.ListBean> data) {

        notifyDataSetChanged();
    }


    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }


    public static interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

}
